* Apply to:  sfmay_2018.xls
* Description:  Figure 3 and Table A1

clear


import excel "...\2204 JEPS\sfmay_2018.xls", sheet("Sheet1") firstrow


* Spatial voting

* Candidate ideal points

* Breed       1.00
* Greenberg   1.87
* Kim        -1.00
* Leno       -0.73

gen head1_correct = 0
replace head1_correct = 1 if d1<=1.435 & head1_choice==1
replace head1_correct = 1 if d1>=1.435 & head1_choice==2
replace head1_correct = . if head1_choice==.

gen head2_correct = 0
replace head2_correct = 1 if d1>=0 & head2_choice==1
replace head2_correct = 1 if d1<=0 & head2_choice==2
replace head2_correct = . if head2_choice==.

gen head3_correct = 0
replace head3_correct = 1 if d1>=0.135 & head3_choice==1
replace head3_correct = 1 if d1<=0.135 & head3_choice==2
replace head3_correct = . if head3_choice==.

gen head4_correct = 0
replace head4_correct = 1 if d1>=0.435 & head4_choice==1
replace head4_correct = 1 if d1<=0.435 & head4_choice==2
replace head4_correct = . if head4_choice==.

gen head5_correct = 0
replace head5_correct = 1 if d1>=0.57 & head5_choice==1
replace head5_correct = 1 if d1<=0.57 & head5_choice==2
replace head5_correct = . if head5_choice==.

gen head6_correct = 0
replace head6_correct = 1 if d1<=-0.865 & head6_choice==1
replace head6_correct = 1 if d1>=-0.865 & head6_choice==2
replace head6_correct = . if head6_choice==.


* Stack head-to-head matchups (6 per respondent)

sort id

expand 6

sort id

by id: gen head = [_n]


* Head-to-head matchups

* 1. Breed vs. Greenberg
* 2. Breed vs. Kim
* 3. Breed vs. Leno
* 4. Greenberg vs. Kim
* 5. Greenberg vs. Leno
* 6. Kim vs. Leno

* Vote for more proximate (correct) alternative

gen vote_spatial = 0
replace vote_spatial = head1_correct if head==1
replace vote_spatial = head2_correct if head==2
replace vote_spatial = head3_correct if head==3
replace vote_spatial = head4_correct if head==4
replace vote_spatial = head5_correct if head==5
replace vote_spatial = head6_correct if head==6


* Table A1.  Difference of Means Tests of the Effects of Information
* Six head-to-head matchups pooled

* Spatial voting

ttest vote_spatial if (treatment1==1 | treatment1==2), by(treatment1)
ttest vote_spatial if (treatment1==1 | treatment1==3), by(treatment1)
ttest vote_spatial if (treatment1==1 | treatment1==5), by(treatment1)

ttest vote_spatial if (treatment1==3 | treatment1==5), by(treatment1)

ttest vote_spatial if (treatment2==6 | treatment2==7), by(treatment2)
ttest vote_spatial if (treatment2==6 | treatment2==8), by(treatment2)

ttest vote_spatial if treatment1==5, by(info_choice2)
ttest vote_spatial if treatment1==5, by(info_choice3)


* Copy results to Excel file Table A1.xlsx

clear

import excel "C:\Users\samacken\Documents\2204 JEPS\Table A1.xlsx", sheet("Sheet1") firstrow


* Recode estimates

replace mean = mean * 100
replace lo = lo * 100
replace hi = hi * 100


* Expand Dataset * 2

gen count = [_n]

expand = 2

sort count

by count: gen row = [_n]

replace mean = 0 if row==2

sort Group count

expand = 2 if Treat=="Control" & row==1

sort Group count row

replace row = 0 in 1
replace mean = 0 in 1


gen order = [_n]-1

sort order


* Figure 3. Effects of Information on Spatial Voting

graph twoway ///
     (bar mean order if order==0, fcolor(white) lcolor(black) barwidth(.25)) ///
     (bar mean order if order==1, fcolor(white) lcolor(black)) ///
     (rcap lo hi order if order==1, lcolor(black)) ///
     (bar mean order if order==3, fcolor(gs12) lcolor(black)) ///
     (rcap lo hi order if order==3, lcolor(black)) ///
     (bar mean order if order==5, fcolor(gs6) lcolor(black)) ///
     (rcap lo hi order if order==5, lcolor(black)) ///
     (bar mean order if order==7, fcolor(black) lcolor(black)) ///
     (rcap lo hi order if order==7, lcolor(black)) ///
     (bar mean order if order==8, fcolor(black) lcolor(black)), ///
     xlabel(none) ylabel(0(10)93) xscale(off) yscale(range(0 90)) ///
	 yline(0, lcolor(black)) ///
	 text(63.8 1 "{bf:53.8}", color(black) size(large)) ///
	 text(70.0 3 "{bf:60.0 *}", color(black) size(large)) ///
	 text(71.4 5 "{bf:61.4 *}", color(black) size(large)) ///
	 text(68.4 7 "{bf:58.4 *}", color(black) size(large)) ///
	 text(-8 1 "{bf:Control}" " ") ///
	 text(-8 3 "{bf:Party}" "{bf:Cues}") ///
	 text(-8 5 "{bf:Voter}" "{bf:Guide}") ///
	 text(-8 7 "{bf:Information}" "{bf:Choice}") ///
	 legend(off) ///
	 ytitle("{bf:Correct Spatial Vote (%)}" " ", size(large)) ///
	 xtitle(" ") ///
	 scheme(s1color) ///
	 note(" " " ") ///
     graphregion(color(white)) plotregion(color(white))

* End
